package com.king.reference.soft;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;

import com.king.reference.CheckRefQueue;
import com.king.reference.MyObject;

/**
 * @author taomk
 * @version 1.0
 * @since 15-1-27 下午10:47
 */
public class SoftReferenceTest {

	public static void main(String [] args) {
		MyObject obj = new MyObject();
		ReferenceQueue<MyObject> softQueue = new ReferenceQueue<>();

		SoftReference<MyObject> softObjRef = new SoftReference<>(obj, softQueue);
		new CheckRefQueue(softQueue).start();
		obj = null;
		System.gc();
		System.out.println("After GC: Soft Get= " + softObjRef.get());
		System.out.println("分配大块内存");
		byte [] b = new byte[1450 * 1024 * 925];
		System.out.println("After new byte[]: Soft Get= " + softObjRef.get());
	}
}
